﻿using Game;
using RecipaediaEX.ComponentsExtra;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XmlUtilities;

namespace RecipaediaEX.Implementation {
    public class BlockProceduralRecipesLoader: IRecipesLoader {
        public int Order => -15;
        public void Initialize() {
        }

        public IEnumerable<IRecipe> GetRecipes() {
            List<IRecipe> recipes = new();
            for (int i = 0; i < BlocksManager.Blocks.Count(); i++) {
                Block block = BlocksManager.Blocks[i];
                IEnumerable<CraftingRecipe> originalRecipes = block.GetProceduralCraftingRecipes();
                foreach (CraftingRecipe originalRecipe in originalRecipes) {
                    float requiredHeatLevel = originalRecipe.RequiredHeatLevel;

                    FormattedRecipe craftingRecipe;
                    if(originalRecipe.RequiredHeatLevel > 0) {
                        craftingRecipe = originalRecipe.ToFormattedRecipe<OriginalSmeltingRecipe>();
                    }
                    else {
                        craftingRecipe = originalRecipe.ToFormattedRecipe<OriginalCraftingRecipe>();
                    }
                    craftingRecipe.SetExtraValue("MatchedResultBlockValues", new int[] { craftingRecipe.ResultValue });
                    recipes.Add(craftingRecipe);
                }
            }
            return recipes;
        }
    }
}
